Starting Out With Visual Basic (7th Edition) by Unknown
Author:Unknown
Language: eng
Format: epub
The Interval property can be set to a value of 1 or greater. The value stored in the Interval
property is the number of milliseconds that elapse between timer events. A millisecond is a
thousandth of a second, so setting the Interval property to 1000 causes a timer event to occur
every second.
In Tutorial 8-7, you examine an application that demonstrates a Timer control.
Tutorial 8-7: The Timer Demo
1. Step 1: Open the Timer Demo project from the sample student programs folder named
Chap8\Timer Demo. The application’s form is shown in Figure 8-30. Notice that the
Timer control appears as a stopwatch in the component tray.
Figure 8-30 Timer Demo form
2. Step 2: Run the application. The form shown in Figure 8-31 appears.
Figure 8-31 Timer Demo
application running
3. Step 3: The number appearing under the Seconds Counter label is initially set to 0,
but it increments every second. After a few seconds, click the Stop Timer button to halt
the timer.
4. Step 4: When you click the Stop Timer button, the button’s text changes to Start
Timer. Click the button again to start the timer.
5. Step 5: After a few seconds, click the Exit button to end the application.
6. Step 6: With the Designer window open, select the Timer control.
7. Step 7: With the Timer control selected, look at the Properties window. The name of
the control is tmrSeconds. Its Enabled property is initially set to True, and its Interval
property is set to 1000.
8. Step 8: Open the Code window and notice that a class-level variable named
intSeconds is declared.
9. Step 9: Look at the tmrSeconds_Tick event handler. The code is as follows:
Private Sub tmrSeconds_Tick(...) Handles tmrSeconds.Tick
' Update the seconds display by one second.
intSeconds += 1
lblCounter.Text = intSeconds.ToString()
End Sub
Each time the tmrSeconds_Tick event handler executes, it adds 1 to intSeconds and
then copies its value to the lblCounter label. Because the Timer control’s Interval
property is set to 1000, this event handler executes every second (unless the Timer
control’s Enabled property equals False).
10. Step 10: The button that stops and starts the timer is named btnToggleTimer. Look at
the btnToggleTimer_Click event handler. The code is as follows:
Private Sub btnToggleTimer_Click(...) Handles btnToggleTimer.Click
' Toggle the timer.
If tmrSeconds.Enabled = True Then
tmrSeconds.Enabled = False
btnToggleTimer.Text = "&Start Timer"
Else
tmrSeconds.Enabled = True
btnToggleTimer.Text = "&Stop Timer"
End If
End Sub
If tmrSeconds.Enabled equals True, the code sets it to False and changes the button’s
text to & Start Timer. Otherwise, it sets the property to True and changes the button’s
text to & Stop Timer.
In Tutorial 8-8 you will use a Timer control to create a game application.
Tutorial 8-8: Creating the Catch Me game
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
The Brazilian Economy since the Great Financial Crisis of 20072008 by Philip Arestis Carolina Troncoso Baltar & Daniela Magalhães Prates(132618)
International Integration of the Brazilian Economy by Elias C. Grivoyannis(106928)
The Art of Coaching by Elena Aguilar(53135)
Flexible Working by Dale Gemma;(23282)
How to Stop Living Paycheck to Paycheck by Avery Breyer(19683)
The Acquirer's Multiple: How the Billionaire Contrarians of Deep Value Beat the Market by Tobias Carlisle(12300)
Thinking, Fast and Slow by Kahneman Daniel(12206)
The Radium Girls by Kate Moore(12001)
The Art of Thinking Clearly by Rolf Dobelli(10379)
Hit Refresh by Satya Nadella(9104)
The Compound Effect by Darren Hardy(8903)
Tools of Titans by Timothy Ferriss(8346)
Atomic Habits: Tiny Changes, Remarkable Results by James Clear(8304)
Turbulence by E. J. Noyes(8001)
A Court of Wings and Ruin by Sarah J. Maas(7785)
Change Your Questions, Change Your Life by Marilee Adams(7717)
Nudge - Improving Decisions about Health, Wealth, and Happiness by Thaler Sunstein(7678)
How to Be a Bawse: A Guide to Conquering Life by Lilly Singh(7458)
Win Bigly by Scott Adams(7168)